package com.hy.controller;

import com.hy.bean.*;
import com.hy.service.LogintableService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Logintable)表控制层
 *
 * @author makejava
 * @since 2024-05-14 22:00:29
 */
@CrossOrigin
@RestController
@RequestMapping("logintable")
public class LogintableController {
    /**
     * 服务对象
     */
    @Resource
    private LogintableService logintableService;

    /* @Description: 登录
    * @Date: 2024/5/15 8:50
    * @paramType: Logintable
    * @Param: logintable 实体类
    * @Return: RespBean
    */

    @PostMapping("/login")
    public RespBean login(Logintable logintable){
        return logintableService.queryByLoginName(logintable);
    }


    /**
     * 退出登录
     * @return 单条数据
     */
    @GetMapping("/logOut/")
    public RespBean LogOut(){
        return RespBean.success("退出成功");
    }

    @GetMapping("/getLoginUserByEmpId/{empId}")
    public RespBean getLoginUserByEmpId(@PathVariable("empId") Integer empId){
        return logintableService.queryByLoginByEmpId(empId);
    }

    @PostMapping("/save")
    public RespBean save(@RequestBody Logintable logintable) {
        return logintableService.save(logintable);
    }

    @GetMapping("/selectAll")
    public PageResult selectAll(@RequestParam(defaultValue = "1") Integer currPage, @RequestParam(defaultValue = "5") Integer pageSize){
        return logintableService.selecrAllLimik(currPage,pageSize);
    }

    @DeleteMapping("/deleteById/{id}")
    public RespBean deleteById(@PathVariable("id") Integer id){
        return logintableService.deleteById(id);
    }

    @PutMapping("/updatePassword")
    public RespBean updatePasswordById(@RequestBody Logintable logintable){
        return logintableService.updatePasswordById(logintable);
    }

    @GetMapping("/getLoginUserByLoginName/{loginName}")
    public RespBean getLoginUserByLoginName(@PathVariable("loginName") String loginName){
        return logintableService.queryByName(loginName);
    }

}

